#include <iostream>
#include <vector>
using namespace std;

vector<int> king(vector<int> a, int n, int m);

int main()
{
    int n, i, m;
    vector<int> a(n+1);
    cout << "enter n and m" << endl;
    cin >> n >> m;
    a[0] = 0;
    for(i = 1;i <= n; i++)
        a[i] = i;
    vector<int> res = king(a, n, m);
    for (auto &a : res)
        cout << a << endl;
    return 0;
}

vector<int> king(vector<int> a, int n, int m)
{
    vector<int> s(n+1);
    vector<int> res;
    int count = 0, num = n, i;
    for (i = 1; i <= n; i++)
    {
        s[i] = 1;
    }
    while (num != 1)
    {
        for (i = 1; i <= n; ++i)
        {
            if (s[i] == 1)
                count++;
            if (count == m)
            {
                res.emplace_back(a[i]);
                s[i] = 0;
                num--;
                count = 0;
            }
        }
    }
    for (i = 1; i <= n; ++i)
        if (s[i] == 1)
            break;
    return res;
}
